
#include "LuaApp.h"
#include "LuaGlobal.h"
#include "LuaPaint.h"
#include "LuaXml.h"
#include "LuaNet.h"
#include "LuaCurl.h"

namespace LuaGui {
	int test_cfunc(lua_State* L)
	{
		int arg = luabridge::Stack<int>::get(L, 1);

		luabridge::push(L, "hello world");
		luabridge::push(L, 12);

		return 2;
	}

	void test_func(std::string text)
	{
		//	printf("---test: %d", text.length());

		std::ofstream outfile;
		outfile.open("D:\\test.jpg", std::ios::binary | std::ios::out | std::ios::trunc);
		outfile << text;
		outfile.close();
		//std::string test("hello world");
		//LuaApp::CallGlobalFunction("__on_net__", "test", test);
	}



	void LuaApp::StaticInit(lua_State* L) {
		Register(L);
	}
	
	static void Exit() {
		GetApplication()->Exit();
	}

	void LuaApp::Register(lua_State* L)
	{
		LuaGlobal::Register(L);
		LuaPaint::Register(L);
		LuaXml::Register(L);
		LuaNet::Register(L);
		LuaCurl::Register(L);

#ifdef USE_LUA
		static bool sUSE_LUA = true;
#else
		static bool sUSE_LUA = false;
#endif // USE_LUA
#ifdef USE_LUV
		static bool sUSE_LUV = true;
#else
		static bool sUSE_LUV = false;
#endif // USE_LUV
#ifdef USE_LUA_CURL
		static bool sUSE_LUA_CURL = true;
#else
		static bool sUSE_LUA_CURL = false;
#endif // USE_LCURL
#ifdef USE_LUA_CJSON
		static bool sUSE_LUA_CJSON = true;
#else
		static bool sUSE_LUA_CJSON = false;
#endif // USE_LUA_CJSON
#ifdef USE_LUA_EXPAT
		static bool sUSE_LUA_EXPAT = true;
#else
		static bool sUSE_LUA_EXPAT = false;
#endif // USE_LUA_EXPAT
		luabridge::getGlobalNamespace(L)
			.beginNamespace("LuaGui")
			.addFunction("Exit", Exit)
			.addFunction("test_func", test_func)
			.addCFunction("test_cfunc", test_cfunc)
			.addProperty("USE_LUA", &sUSE_LUA, false)
			.addProperty("USE_LUV", &sUSE_LUV, false)
			.addProperty("USE_LCURL", &sUSE_LUA_CURL, false)
			.addProperty("USE_LUA_CJSON", &sUSE_LUA_CJSON, false)
			.addProperty("USE_LUA_EXPAT", &sUSE_LUA_EXPAT, false)
			.beginNamespace("VirtualKey")
			.addProperty("VK_UNKNOWN", (unsigned int*)&LuaGui::EVirtualKey::KEY_UNKNOWN)
			.addProperty("VK_0", (unsigned int*)&LuaGui::EVirtualKey::KEY_0)
			.addProperty("VK_1", (unsigned int*)&LuaGui::EVirtualKey::KEY_1)
			.addProperty("VK_2", (unsigned int*)&LuaGui::EVirtualKey::KEY_2)
			.addProperty("VK_3", (unsigned int*)&LuaGui::EVirtualKey::KEY_3)
			.addProperty("VK_4", (unsigned int*)&LuaGui::EVirtualKey::KEY_4)
			.addProperty("VK_5", (unsigned int*)&LuaGui::EVirtualKey::KEY_5)
			.addProperty("VK_6", (unsigned int*)&LuaGui::EVirtualKey::KEY_6)
			.addProperty("VK_7", (unsigned int*)&LuaGui::EVirtualKey::KEY_7)
			.addProperty("VK_8", (unsigned int*)&LuaGui::EVirtualKey::KEY_8)
			.addProperty("VK_9", (unsigned int*)&LuaGui::EVirtualKey::KEY_9)
			.addProperty("VK_A", (unsigned int*)&LuaGui::EVirtualKey::KEY_A)
			.addProperty("VK_B", (unsigned int*)&LuaGui::EVirtualKey::KEY_B)
			.addProperty("VK_C", (unsigned int*)&LuaGui::EVirtualKey::KEY_C)
			.addProperty("VK_D", (unsigned int*)&LuaGui::EVirtualKey::KEY_D)
			.addProperty("VK_E", (unsigned int*)&LuaGui::EVirtualKey::KEY_E)
			.addProperty("VK_F", (unsigned int*)&LuaGui::EVirtualKey::KEY_F)
			.addProperty("VK_G", (unsigned int*)&LuaGui::EVirtualKey::KEY_G)
			.addProperty("VK_H", (unsigned int*)&LuaGui::EVirtualKey::KEY_H)
			.addProperty("VK_I", (unsigned int*)&LuaGui::EVirtualKey::KEY_I)
			.addProperty("VK_J", (unsigned int*)&LuaGui::EVirtualKey::KEY_J)
			.addProperty("VK_K", (unsigned int*)&LuaGui::EVirtualKey::KEY_K)
			.addProperty("VK_L", (unsigned int*)&LuaGui::EVirtualKey::KEY_L)
			.addProperty("VK_M", (unsigned int*)&LuaGui::EVirtualKey::KEY_M)
			.addProperty("VK_N", (unsigned int*)&LuaGui::EVirtualKey::KEY_N)
			.addProperty("VK_O", (unsigned int*)&LuaGui::EVirtualKey::KEY_O)
			.addProperty("VK_P", (unsigned int*)&LuaGui::EVirtualKey::KEY_P)
			.addProperty("VK_Q", (unsigned int*)&LuaGui::EVirtualKey::KEY_Q)
			.addProperty("VK_R", (unsigned int*)&LuaGui::EVirtualKey::KEY_R)
			.addProperty("VK_S", (unsigned int*)&LuaGui::EVirtualKey::KEY_S)
			.addProperty("VK_T", (unsigned int*)&LuaGui::EVirtualKey::KEY_T)
			.addProperty("VK_U", (unsigned int*)&LuaGui::EVirtualKey::KEY_U)
			.addProperty("VK_V", (unsigned int*)&LuaGui::EVirtualKey::KEY_V)
			.addProperty("VK_W", (unsigned int*)&LuaGui::EVirtualKey::KEY_W)
			.addProperty("VK_X", (unsigned int*)&LuaGui::EVirtualKey::KEY_X)
			.addProperty("VK_Y", (unsigned int*)&LuaGui::EVirtualKey::KEY_Y)
			.addProperty("VK_Z", (unsigned int*)&LuaGui::EVirtualKey::KEY_Z)

			.addProperty("VK_NUMPAD0", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD0)
			.addProperty("VK_NUMPAD1", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD1)
			.addProperty("VK_NUMPAD2", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD2)
			.addProperty("VK_NUMPAD3", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD3)
			.addProperty("VK_NUMPAD4", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD4)
			.addProperty("VK_NUMPAD5", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD5)
			.addProperty("VK_NUMPAD6", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD6)
			.addProperty("VK_NUMPAD7", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD7)
			.addProperty("VK_NUMPAD8", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD8)
			.addProperty("VK_NUMPAD9", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD9)

			.addProperty("VK_F1", (unsigned int*)&LuaGui::EVirtualKey::KEY_F1)
			.addProperty("VK_F2", (unsigned int*)&LuaGui::EVirtualKey::KEY_F2)
			.addProperty("VK_F3", (unsigned int*)&LuaGui::EVirtualKey::KEY_F3)
			.addProperty("VK_F4", (unsigned int*)&LuaGui::EVirtualKey::KEY_F4)
			.addProperty("VK_F5", (unsigned int*)&LuaGui::EVirtualKey::KEY_F5)
			.addProperty("VK_F6", (unsigned int*)&LuaGui::EVirtualKey::KEY_F6)
			.addProperty("VK_F7", (unsigned int*)&LuaGui::EVirtualKey::KEY_F7)
			.addProperty("VK_F8", (unsigned int*)&LuaGui::EVirtualKey::KEY_F8)
			.addProperty("VK_F9", (unsigned int*)&LuaGui::EVirtualKey::KEY_F9)
			.addProperty("VK_F10", (unsigned int*)&LuaGui::EVirtualKey::KEY_F10)
			.addProperty("VK_F11", (unsigned int*)&LuaGui::EVirtualKey::KEY_F11)
			.addProperty("VK_F12", (unsigned int*)&LuaGui::EVirtualKey::KEY_F12)
			.addProperty("VK_F13", (unsigned int*)&LuaGui::EVirtualKey::KEY_F13)
			.addProperty("VK_F14", (unsigned int*)&LuaGui::EVirtualKey::KEY_F14)
			.addProperty("VK_F15", (unsigned int*)&LuaGui::EVirtualKey::KEY_F15)
			.addProperty("VK_F16", (unsigned int*)&LuaGui::EVirtualKey::KEY_F16)
			.addProperty("VK_F17", (unsigned int*)&LuaGui::EVirtualKey::KEY_F17)
			.addProperty("VK_F18", (unsigned int*)&LuaGui::EVirtualKey::KEY_F18)
			.addProperty("VK_F19", (unsigned int*)&LuaGui::EVirtualKey::KEY_F19)
			.addProperty("VK_F20", (unsigned int*)&LuaGui::EVirtualKey::KEY_F20)
			.addProperty("VK_F21", (unsigned int*)&LuaGui::EVirtualKey::KEY_F21)
			.addProperty("VK_F22", (unsigned int*)&LuaGui::EVirtualKey::KEY_F22)
			.addProperty("VK_F23", (unsigned int*)&LuaGui::EVirtualKey::KEY_F23)
			.addProperty("VK_F24", (unsigned int*)&LuaGui::EVirtualKey::KEY_F24)

			.addProperty("VK_LSHIFT", (unsigned int*)&LuaGui::EVirtualKey::KEY_LSHIFT)
			.addProperty("VK_RSHIFT", (unsigned int*)&LuaGui::EVirtualKey::KEY_RSHIFT)
			.addProperty("VK_LCONTROL", (unsigned int*)&LuaGui::EVirtualKey::KEY_LCONTROL)
			.addProperty("VK_RCONTROL", (unsigned int*)&LuaGui::EVirtualKey::KEY_RCONTROL)
			.addProperty("VK_LALT", (unsigned int*)&LuaGui::EVirtualKey::KEY_LALT)
			.addProperty("VK_RALT", (unsigned int*)&LuaGui::EVirtualKey::KEY_RALT)
			.addProperty("VK_LGUI", (unsigned int*)&LuaGui::EVirtualKey::KEY_LGUI)
			.addProperty("VK_RGUI", (unsigned int*)&LuaGui::EVirtualKey::KEY_RGUI)

			.addProperty("VK_TAB", (unsigned int*)&LuaGui::EVirtualKey::KEY_TAB)
			.addProperty("VK_CLEAR", (unsigned int*)&LuaGui::EVirtualKey::KEY_CLEAR)
			.addProperty("VK_RETURN", (unsigned int*)&LuaGui::EVirtualKey::KEY_RETURN)
			.addProperty("VK_PAUSE", (unsigned int*)&LuaGui::EVirtualKey::KEY_PAUSE)
			.addProperty("VK_CAPSLOCK", (unsigned int*)&LuaGui::EVirtualKey::KEY_CAPSLOCK)
			.addProperty("VK_BACKSPACE", (unsigned int*)&LuaGui::EVirtualKey::KEY_BACKSPACE)
			.addProperty("VK_ESCAPE", (unsigned int*)&LuaGui::EVirtualKey::KEY_ESCAPE)
			.addProperty("VK_SPACE", (unsigned int*)&LuaGui::EVirtualKey::KEY_SPACE)

			.addProperty("VK_HOME", (unsigned int*)&LuaGui::EVirtualKey::KEY_HOME)
			.addProperty("VK_END", (unsigned int*)&LuaGui::EVirtualKey::KEY_END)
			.addProperty("VK_LEFT", (unsigned int*)&LuaGui::EVirtualKey::KEY_LEFT)
			.addProperty("VK_UP", (unsigned int*)&LuaGui::EVirtualKey::KEY_UP)
			.addProperty("VK_RIGHT", (unsigned int*)&LuaGui::EVirtualKey::KEY_RIGHT)
			.addProperty("VK_DOWN", (unsigned int*)&LuaGui::EVirtualKey::KEY_DOWN)
			.addProperty("VK_INSERT", (unsigned int*)&LuaGui::EVirtualKey::KEY_INSERT)
			.addProperty("VK_DELETE", (unsigned int*)&LuaGui::EVirtualKey::KEY_DELETE)
			.addProperty("VK_PAGEUP", (unsigned int*)&LuaGui::EVirtualKey::KEY_PAGEUP)
			.addProperty("VK_PAGEDOWN", (unsigned int*)&LuaGui::EVirtualKey::KEY_PAGEDOWN)

			.addProperty("VK_EXCLAIM", (unsigned int*)&LuaGui::EVirtualKey::KEY_EXCLAIM)           // '!'
			.addProperty("VK_QUOTEDBL", (unsigned int*)&LuaGui::EVirtualKey::KEY_QUOTEDBL)         // '"'
			.addProperty("VK_HASH", (unsigned int*)&LuaGui::EVirtualKey::KEY_HASH)                 // '#',
			.addProperty("VK_PERCENT", (unsigned int*)&LuaGui::EVirtualKey::KEY_PERCENT)           // '%',
			.addProperty("VK_DOLLAR", (unsigned int*)&LuaGui::EVirtualKey::KEY_DOLLAR)             // '$'
			.addProperty("VK_AMPERSAND", (unsigned int*)&LuaGui::EVirtualKey::KEY_AMPERSAND)       // '&',
			.addProperty("VK_QUOTE", (unsigned int*)&LuaGui::EVirtualKey::KEY_QUOTE)               // '\'',
			.addProperty("VK_LEFTPAREN", (unsigned int*)&LuaGui::EVirtualKey::KEY_LEFTPAREN)       // '(',
			.addProperty("VK_RIGHTPAREN", (unsigned int*)&LuaGui::EVirtualKey::KEY_RIGHTPAREN)     // ')',
			.addProperty("VK_ASTERISK", (unsigned int*)&LuaGui::EVirtualKey::KEY_ASTERISK)         // '*',
			.addProperty("VK_PLUS", (unsigned int*)&LuaGui::EVirtualKey::KEY_PLUS)                 // '+',
			.addProperty("VK_COMMA", (unsigned int*)&LuaGui::EVirtualKey::KEY_COMMA)               // ',',
			.addProperty("VK_MINUS", (unsigned int*)&LuaGui::EVirtualKey::KEY_MINUS)               // '-',
			.addProperty("VK_PERIOD", (unsigned int*)&LuaGui::EVirtualKey::KEY_PERIOD)             // '.',
			.addProperty("VK_SLASH", (unsigned int*)&LuaGui::EVirtualKey::KEY_SLASH)               // '/',
			.addProperty("VK_UNDERSCORE", (unsigned int*)&LuaGui::EVirtualKey::KEY_UNDERSCORE)     // '_',
			.addProperty("VK_QUESTION", (unsigned int*)&LuaGui::EVirtualKey::KEY_QUESTION)         // '?',
			.addProperty("VK_LESS", (unsigned int*)&LuaGui::EVirtualKey::KEY_LESS)                 // '<',
			.addProperty("VK_GREATER", (unsigned int*)&LuaGui::EVirtualKey::KEY_GREATER)           // '>',
			.addProperty("VK_COLON", (unsigned int*)&LuaGui::EVirtualKey::KEY_COLON)               // ':',
			.addProperty("VK_CARET", (unsigned int*)&LuaGui::EVirtualKey::KEY_CARET)               // '^',
			.addProperty("VK_AT", (unsigned int*)&LuaGui::EVirtualKey::KEY_AT)                     // '@',
			.addProperty("VK_SEMICOLON", (unsigned int*)&LuaGui::EVirtualKey::KEY_SEMICOLON)       // '',
			.addProperty("VK_RIGHTBRACKET", (unsigned int*)&LuaGui::EVirtualKey::KEY_RIGHTBRACKET) // ']',
			.addProperty("VK_LEFTBRACKET", (unsigned int*)&LuaGui::EVirtualKey::KEY_LEFTBRACKET)   // '[',

			.addProperty("VK_NUMPAD_PLUS", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD_PLUS)
			.addProperty("VK_NUMPAD_MINUS", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD_MINUS)
			.addProperty("VK_NUMPAD_MULTIPLY", (unsigned int*)&LuaGui::EVirtualKey::KEY_NUMPAD_MULTIPLY)
			.endNamespace()
			// mouse virtual key
			.beginNamespace("VirtualMouseKey")
			.addProperty("VMK_NONE", (unsigned int*)&LuaGui::EVirtualMouseKey::KEY_NONE)
			.addProperty("VMK_LEFT", (unsigned int*)&LuaGui::EVirtualMouseKey::KEY_LEFT)
			.addProperty("VMK_MIDDLE", (unsigned int*)&LuaGui::EVirtualMouseKey::KEY_MIDDLE)
			.addProperty("VMK_RIGHT", (unsigned int*)&LuaGui::EVirtualMouseKey::KEY_RIGHT)
			.endNamespace()
			.endNamespace();
	}
}

